﻿<%@ Page Language="VB" %>

<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    'Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    '    Try
    '        ReportViewer1.ProcessingMode = ProcessingMode.Local

    '        'Dim rep As LocalReport = ReportViewer1.LocalReport
    '        Dim sessionStaffCode As Integer = Convert.ToInt32(Session("staff_code"))
    '        Dim GroupCode As Integer = Convert.ToInt32(Request.QueryString("group_code"))
    '        Dim DepartmentCode As Integer = Convert.ToInt32(Request.QueryString("department_code"))
    '        Dim MainSystemCode As Integer = Convert.ToInt32(Request.QueryString("main_system_code"))
    '        Dim MenuSystemCode As Integer = Convert.ToInt32(Request.QueryString("menu_system_code"))
    '        Dim AuthDeptStatus As Integer = Convert.ToInt32(Request.QueryString("auth_department_status"))

    '        'rep.ReportPath = "Reports\report_stp_auth_group5.rdlc"
    '        ReportViewer1.LocalReport.ReportPath = "Reports\report_stp_auth_group5.rdlc"
    '        Dim ds As DataSet = GetDataReport(DepartmentCode, GroupCode, AuthDeptStatus, sessionStaffCode, MenuSystemCode, MainSystemCode)

    '        Dim rds As New ReportDataSource

    '        Dim int As Integer = ds.Tables(0).Rows.Count

    '        rds.Value = ds.Tables(0)
    '        'rep.DataSources.Add(rds)

    '        ReportViewer1.LocalReport.DataSources.Add(rds)

    '        ReportViewer1.DataBind()

    '        ReportViewer1.LocalReport.Refresh()

    '    Catch ex As Exception
    '        GenericHelper.ShowAlert(Me, ex)
    '    End Try

    'End Sub

    'Public Shared Function GetDataReport(ByVal department_code As Int32, ByVal group_code As Int32, ByVal auth_department_status As Int32, ByVal staff_code As Int32, ByVal menu_system_code As Int32, ByVal main_system_code As Int32) As DataSet

    '    Dim dt As New DataTable
    '    Dim i As Integer
    '    Dim a As Integer
    '    Dim strLastGroup As String = ""

    '    ' =========================================================================
    '    ' Get table
    '    ' =========================================================================
    '    Dim tbl = CodeMatrix.Utilities.CodeHelper.GetDataTable( _
    '        "select * from master_type")

    '    dt.Columns.Add("ระบบงาน", Type.GetType("System.String"))

    '    For i = 0 To tbl.Rows.Count - 1
    '        dt.Columns.Add(tbl.Rows(i)("type_name"), Type.GetType("System.String"))
    '    Next

    '    Dim tblAuthGroup = CodeMatrix.Utilities.CodeHelper.GetDataTable( _
    '        "exec USP_List_stp_auth_group1 @staff_code,@group_code,@department_code,@main_system_code,@menu_system_code,@auth_department_status", _
    '         New SqlParameter("@staff_code", staff_code), _
    '         New SqlParameter("@group_code", group_code), _
    '         New SqlParameter("@department_code", department_code), _
    '         New SqlParameter("@main_system_code", main_system_code), _
    '         New SqlParameter("@menu_system_code", menu_system_code), _
    '         New SqlParameter("@auth_department_status", auth_department_status) _
    '        )

    '    Dim newRow As DataRow
    '    Dim iReportRowCount As Integer = 0

    '    For a = 0 To tblAuthGroup.Rows.Count - 1
    '        If (tblAuthGroup.Rows(a)("menu_system_name") = strLastGroup) Then
    '            ' same group
    '            newRow(tblAuthGroup.Rows(a)("type_name")) = "*"
    '        Else
    '            ' save the old group
    '            ' if it is first row do nothing
    '            If (0 < iReportRowCount) Then
    '                dt.Rows.Add(newRow)
    '            End If

    '            ' new group
    '            newRow = dt.NewRow

    '            ' increment the counter
    '            iReportRowCount = iReportRowCount + 1

    '            newRow(tblAuthGroup.Rows(a)("type_name")) = "*"
    '            newRow("ระบบงาน") = tblAuthGroup.Rows(a)("menu_system_name")

    '            ' save current group
    '            strLastGroup = tblAuthGroup.Rows(a)("menu_system_name")

    '        End If
    '    Next

    '    ' for the last record
    '    dt.Rows.Add(newRow)

    '    Dim ds As DataSet = New DataSet
    '    ds.Tables.Add(dt)
    '    Return ds

    'End Function
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
            Height="500px" Width="100%">
                <LocalReport ReportPath="Reports\report_stp_auth_group4.rdlc">
                    <DataSources>
                        <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" 
                            Name="report_stp_auth_group_USP_List_stp_auth_group1" />
                    </DataSources>
                </LocalReport>
            </rsweb:ReportViewer>
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
                SelectMethod="GetDepartmentForAuthGroup" 
                
                TypeName="StpAuthenGroup" 
                OldValuesParameterFormatString="original_{0}">
                <SelectParameters>
                    <asp:SessionParameter DefaultValue="0" Name="staff_code" 
                        SessionField="staff_code" Type="Int32" />
                    <asp:QueryStringParameter DefaultValue="0" Name="department_code" 
                        QueryStringField="department_code" Type="Int32" />
                    <asp:QueryStringParameter DefaultValue="0" Name="group_code" 
                        QueryStringField="group_code" Type="Int32" />
                    <asp:QueryStringParameter DefaultValue="0" Name="auth_group_status" 
                        QueryStringField="auth_group_status" Type="Int32" />
                    <asp:QueryStringParameter DefaultValue="0" Name="main_system_code" 
                        QueryStringField="main_system_code" Type="Int32" />
                    <asp:QueryStringParameter DefaultValue="0" Name="menu_system_code" 
                        QueryStringField="menu_system_code" Type="Int32" />
                </SelectParameters>
            </asp:ObjectDataSource>
        </div>
    </form>
</body>
</html>
